package com.jsm.twentyfour.service;

import com.jsm.twentyfour.domain.Score;
import com.jsm.twentyfour.domain.ScoreExample;
import com.jsm.twentyfour.dto.ScoreDTO;
import com.jsm.twentyfour.mapper.BaseMapper;
import com.jsm.twentyfour.mapper.ScoreMapper;
import com.jsm.twentyfour.transfer.ScoreTransfer;
import com.sun.org.apache.bcel.internal.generic.RETURN;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * create by jsm on 2019/1/24
 */
@Service
public class ScoreService extends BaseService <Score, ScoreDTO, ScoreExample> {
    @Resource
    private ScoreMapper scoreMapper;

    @Override
    public BaseMapper <Score, ScoreExample> mapper() {
        return scoreMapper;
    }

    @Override
    public Class <ScoreDTO> getDTOClass() {
        return ScoreDTO.class;
    }

    @Override
    public ScoreDTO transfer(Score score) {
        return ScoreTransfer.transfer(score);
    }

    public ScoreDTO getByUserId(Long userId) {
        ScoreExample example = new ScoreExample();
        example.createCriteria().andUserIdEqualTo(userId);
        return getByExample(example);
    }

    public void computeSuccess(Long userId) {
        ScoreDTO scoreDTO = getByUserId(userId);
        updateSelective(ScoreTransfer.transfer(scoreDTO));
    }
}
